package api

import (
	"context"
	"doctor_srv/model"
	"doctor_srv/model/dao"
	pb "doctor_srv/proto"
)

func (d *DoctorServer) RoomList(ctx context.Context, req *pb.RoomListRequest) (resp *pb.RoomListResponse, err error) {

	list := dao.GetRoomList(req.Name)
	var result []*pb.Room
	for _, hospital := range list {
		result = append(result, &pb.Room{
			Id:    int32(hospital.ID),
			Name:  hospital.Name,
			Pid:   int32(hospital.ParentID),
			Rooms: Class(hospital.Children),
		})
	}
	return &pb.RoomListResponse{
		Rooms: result,
	}, nil
}
func Class(room []model.Room) []*pb.Room {
	var result []*pb.Room
	for _, hospital := range room {
		result = append(result, &pb.Room{
			Id:    int32(hospital.ID),
			Name:  hospital.Name,
			Pid:   int32(hospital.ParentID),
			Rooms: Class(hospital.Children),
		})
	}
	return result
}
